<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    public function success(string $message,  $data = [], $code = 200):\Illuminate\Http\Response
    {
        return response(['message' => $message,'status' => 'success', 'code' => $code, 'data' => $data]);
    }

    /**
     * 失败响应
     *
     * @param string $message
     * @param integer $httpCode
     * @return \Illuminate\Http\Response
     */
    public function error(string $message = '', $data = null, int $code = 500)
    {

//        return response([
//            'code' => $code,
//            'status' => 'error',
//            'message' => $message,
//            'data' => $data
//        ]);
//        手动抛出错误
        abort($code, $message);
    }
}
